<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Hash;
use DB;
class OrderController extends Controller
{
	//订单列表
    public function index(Request $request)
    {
    	$title = "这是列表";
    	//查询数据
    	
    	$data  = DB::table('order as o')
    			->leftJoin('user as u','u.id','=','o.uid')
                ->leftJoin('shop as s','s.id','=','o.sid')
    			->select('u.username','s.shopname','o.*')
    			->where(function($query) use ($request){
    			$query -> where('u.username','like','%'.$request->input('keywords').'%');
    			}) -> paginate($request -> input('num',10));
    			
    
    	
    	return view('admin.order.index',['title' => $title,'data' => $data,'request' => $request -> all()]);
    }

    //详情
    public function detail($id)
    {
        $title = '这是详情';
        $data  = DB::table('order') -> where('id','=',$id) -> first();
        // dd($data);
        return view('admin.order.detail',['title' => $title,'data'=>$data]);
    }
    //编辑
    //
    public function edit($id)
    {
        
        $title = '用户编辑';
        //查询数据
        $data = DB::table('order') -> where('id','=',$id) -> first();
        //解析模板
        return view('admin/order/edit',['title' => $title,'data'=> $data]);
    }
    //删除
    public function delete($id)
    {
        $title = '这是删除';
        $data = DB::table('order') -> where('id','=','$id') -> delete();
        if($res)
        {
            return redirect('/admin/order/index') -> with(['success' => '删除成功']);
        }else{
            return back() -> with(['fail' => '删除失败']);
        }

    }

}
